﻿
@{
    ViewBag.Title = "ArchiveAJQuery";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var Info = ViewBag.Info as List<SGArchiveSystem7xDB.T_ArchiveFields>;
    List<SGArchiveSystem7xDB.V_ArchiveWord> Word = ViewBag.Word ;
    List<SGArchiveSystem7x.Models.CComboboxModel> Dept = ViewBag.dept;
}

<div>
    <div style="padding-bottom: 10px">
        <select id="ArchiveInit_ArchiveAJInfo_cmbField" class="easyui-combobox" label="@ViewBag.Text0" labelalign="right" labelwidth="80px" data-options="editable:false" name="cmbStatus" style="width:100%" panelHeight="auto">
            @{
            foreach (var en in Info)
            {
                if (en.AF_QUERY == 1)
                {
                    <option value="@en.AF_ID-@en.AF_TYPE-@en.AF_FIELD-@en.AF_NAME">@en.AF_NAME</option>
            }
        }
            }
        </select>
    </div>
    <div style="padding-bottom: 10px">
        <div id="divWhereText"><select id="cmbAdvWhereText" class="easyui-combobox" label="@ViewBag.Text1" labelalign="right" labelwidth="80px" name="cmbAdvWhereText" style="width:100%" editable="false" panelHeight="auto"> <option value="like" selected="selected">@ViewBag.Text2</option><option value="=">@ViewBag.Text3</option></select></div>
        <div id="divWhereWord">@ViewBag.Text1<select id="cmbAdvWhereWord" class="easyui-combobox" label="@ViewBag.Text1" labelalign="right" labelwidth="80px" name="cmbAdvWhereWord" style="width:100%" editable="false" panelHeight="auto"><option value="=">@ViewBag.Text3</option></select></div>
        <div id="divWhereMath">
            <select id="cmbAdvWhereMath" class="easyui-combobox" label="@ViewBag.Text1" labelalign="right" labelwidth="80px" name="cmbAdvWhereMath" style="width:100%" editable="false" panelHeight="auto">
                <option value="=" selected="selected">=</option>
                <option value=">=">>=</option>
                <option value="<="><=</option>
            </select>
        </div>
    </div>
    <div style="padding-bottom: 10px">
        <div id="divTxtContent"><input class="easyui-textbox" type="text" id="txtAdvContent"  label="@ViewBag.Text4" labelalign="right" labelwidth="80px" name="txtAdvContent" style="width:100%" value="" /></div>
        <div id="divCmbContent"><select id="cmbAdvContent" data-options="valueField:'id', textField:'text'"  label="@ViewBag.Text4" labelalign="right" labelwidth="80px" class="easyui-combobox" name="cmbAdvContent" style="width:100%" editable="false" panelHeight="auto"></select></div>
        <div id="divDateContent"><input id="dateAdvContent" type="text" class="easyui-datebox"  label="@ViewBag.Text4" labelalign="right" labelwidth="80px" data-options="editable:false" name="dateAdvContent" style="width:100%" editable="false" panelHeight="auto" /></div>
    </div>
    <div style="padding-bottom: 10px">
        <select id="cmbAdvAnd" class="easyui-combobox" name="cmbAdvAnd" style="width:100%"  label="@ViewBag.Text7" labelalign="right" labelwidth="80px" editable="false" panelHeight="auto"><option value="and" selected="selected">@ViewBag.Text5</option><option value="or">@ViewBag.Text6</option></select>
    </div>
    <div align="right" style="width: 540px;padding-top:5px;padding-bottom:5px">
        <a href="javascript:void(0);" class="easyui-linkbutton button-blue" iconCls="icon-add" onclick="AddWhere()" style="height: 30px;width:140px">@ViewBag.Text8</a>
    </div>
    <div data-options="region:'center',split:false" style="height:180px;border:0px;">
        <table id="dg" class="easyui-datagrid" style="width:100%;height:180px" title="@ViewBag.Text9" data-options="
                singleSelect:false,
                autoRowHeight:false,
                fitColumns:true,
                striped:true,
                checkOnSelect:false,
                selectOnCheck:false,
                collapsible:true">
            <thead>
                <tr>
                    <th field="fields" width="80" align="center">@ViewBag.Text10</th>
                    <th field="where" width="50" align="center">@ViewBag.Text11</th>
                    <th field="value" width="100" align="center">@ViewBag.Text12</th>
                    <th field="andor" width="50" align="center">@ViewBag.Text13</th>
                    <th field="id" width="50" align="center" formatter="formatDel">@ViewBag.Text14</th>
                </tr>
            </thead>
        </table>
    </div>
    <div data-options="region:'south',split:false" style="height:50px;border:0px;padding-top:5px">
        <div align="right" style="width: 540px;">
            <a href="javascript:void(0);" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="StartQuery()" style="height: 30px;width:140px">@ViewBag.Text15</a>
        </div>
    </div>
</div>
    <script>
        var array = @Html.Raw(Json.Encode(Word));
        var arrayd = @Html.Raw(Json.Encode(Dept));
        var griddatas = [];
        var selectid = 0;


        $(document).ready(function () {
            fieldsChange();
            $("#ArchiveInit_ArchiveAJInfo_cmbField").combobox({
                onChange: function (n, o) {
                    fieldsChange();
                }
            });
        });

        function fieldsChange() {
            var type = $('#ArchiveInit_ArchiveAJInfo_cmbField').combobox('getValue');
            var word = type.split('-')[3];
            type = type.split('-')[1];
           // alert(type);
            //var txt = $('#cmbAdvFields').combobox('getText');
            $('#txtAdvContent').textbox('setValue', '');

            if (type == "@ViewBag.Text16" || type == "@ViewBag.Text17") {
                $('#divWhereText').css('display', '');
                $('#divWhereWord').css('display', 'none');
                $('#divWhereMath').css('display', 'none');
                $('#divTxtContent').css('display', '');
                $('#divCmbContent').css('display', 'none');
                $('#divDateContent').css('display', 'none');
            }
            else if (type == "@ViewBag.Text18" || type == "@ViewBag.Text19") {
                $('#divWhereText').css('display', 'none');
                $('#divWhereWord').css('display', 'none');
                $('#divWhereMath').css('display', '');
                $('#divTxtContent').css('display', '');
                $('#divCmbContent').css('display', 'none');
                $('#divDateContent').css('display', 'none');
            }
            else if (type == "@ViewBag.Text20") {
                $('#divWhereText').css('display', 'none');
                $('#divWhereWord').css('display', 'none');
                $('#divWhereMath').css('display', '');
                $('#divTxtContent').css('display', 'none');
                $('#divCmbContent').css('display', 'none');
                $('#divDateContent').css('display', '');
            }
            else if (type == "@ViewBag.Text21"){
                $('#divWhereText').css('display', 'none');
                $('#divWhereWord').css('display', '');
                $('#divWhereMath').css('display', 'none');
                $('#divTxtContent').css('display', 'none');
                $('#divCmbContent').css('display', '');
                $('#divDateContent').css('display', 'none');
                var data = [];
                for (var i = 0; i < arrayd.length; i++) {
                    data.push({ "text": arrayd[i].Text, "id": arrayd[i].ID });
                }
                $("#cmbAdvContent").combobox("loadData", data);
                $("#cmbAdvContent").combobox("setValue", data[0].id);

            }
            else  {
                $('#divWhereText').css('display', 'none');
                $('#divWhereWord').css('display', '');
                $('#divWhereMath').css('display', 'none');
                $('#divTxtContent').css('display', 'none');
                $('#divCmbContent').css('display', '');
                $('#divDateContent').css('display', 'none');
                var data = [];
                for (var i = 0; i < array.length; i++) {
                    if (array[i].WT_NAME == word) {
                        data.push({ "text": array[i].WD_NAME, "id": array[i].WD_ID });
                    }
                }
                $("#cmbAdvContent").combobox("loadData", data);
                $("#cmbAdvContent").combobox("setValue", data[0].id);
            }
        }

        function AddWhere() {
            //var txt = $('#ArchiveInit_ArchiveAJInfo_cmbField').combobox('getText');//归档号
            var type = $('#ArchiveInit_ArchiveAJInfo_cmbField').combobox('getValue');//14-唯一-DH-归档号
            var txt = type.split('-')[3];
            var field = type.split('-')[2];
            //alert($('#cmbAdvContent').combobox("getValue"));
            var where = '', value = '', Wvalue = '';//, valueid = '';
            var value1= '';
            //var v02 = type.split(',')[3];
            type = type.split('-')[1];

            if (type == "@ViewBag.Text16" || type == "@ViewBag.Text17") {
                where = $('#cmbAdvWhereText').combobox("getText");//包含
                Wvalue = $('#cmbAdvWhereText').combobox("getValue");
                value = $("#txtAdvContent").val();//内容
                value1 = value;
                //valueid = '0';
                if (value == '') {
                    $.messager.alert('@ViewBag.Text22', '@ViewBag.Text23', 'info');
                    return;
                }
            }
            else if (type == "@ViewBag.Text18" || type == "@ViewBag.Text19") {
                where = $('#cmbAdvWhereMath').combobox("getText");
                Wvalue = $('#cmbAdvWhereMath').combobox("getValue");
                value = $('#txtAdvContent').val();
                //valueid = '0';
                value1 = value;
                if (isRealNum(value)) {
                    if (value.length != 4 && type == '@ViewBag.Text19') {
                        $.messager.alert('@ViewBag.Text22', '@ViewBag.Text24','info');
                        return;
                    }
                }
                else {
                    $.messager.alert('@ViewBag.Text22', '@ViewBag.Text23', 'info');
                    return;
                }

            }
            else if (type == "@ViewBag.Text20") {
                where = $('#cmbAdvWhereMath').combobox("getText");
                Wvalue = $('#cmbAdvWhereMath').combobox("getValue");
                value = $('#dateAdvContent').datebox("getValue");
                //valueid = '0';
                value1 = value;
            }
            else {
                where = $('#cmbAdvWhereWord').combobox("getText");
                Wvalue = $('#cmbAdvWhereWord').combobox("getValue");
                //value = $('#cmbAdvContent').combobox("getText");
                value = $('#cmbAdvContent').combobox("getValue");
                value1 = $('#cmbAdvContent').combobox("getText");
            }

            griddatas.push({ "id": selectid, "fields": txt, "where": where, "value": value1, "andor": $('#cmbAdvAnd').combobox("getText"), "Wvalue": Wvalue, "fd": field, "content": value });
            //alert(griddatas[0].id)
            $("#dg").datagrid("loadData", { "total": "50", "rows": griddatas });
            //alert(griddatas[0].id)
            selectid++;
        }

        function del(value) {
            for (var i = 0; i < griddatas.length; i++) {
                if (griddatas[i].id == value) {
                    griddatas.splice(i, 1);
                    break;
                }
            }
            $("#dg").datagrid("loadData", { "total": "50", rows: griddatas });
        }

        function formatDel(value, row) {
            return "<a href='javascript:void(0);' onclick='del(" + value + ")'>" + '@ViewBag.Text14' + "</a>";
        }

        function StartQuery()
        {
            var sql = "";
            if (griddatas.length > 0) {
                for (var i = 0; i < griddatas.length; i++) {
                    if (griddatas[i].Wvalue == "like") {
                        sql = sql + griddatas[i].fd + ' ' + griddatas[i].Wvalue + ' \'%' + griddatas[i].content + '%\'';
                    }
                    else {
                        sql = sql + griddatas[i].fd + ' ' + griddatas[i].Wvalue + ' \'' + griddatas[i].content + '\'';
                    }
                    if ((i + 1) < griddatas.length) {
                        if (griddatas[i].andor == "@ViewBag.Text5") {
                            sql = sql  + " and ";
                        }
                        else {
                            sql = sql + " or ";
                        }
                    }
                }
            }
            $.ajax({
                url: "/ArchiveInit/Get_ajaxArchiveQuery",
                dataType: "text",
                type: "post",
                data: { sql: sql },
                success: function (data) {
                    parent.window.CloseWinQueryGrid();
                    ///window.location.href = "/ArchiveInit/ArchiveAJ";
                }
            });
        }
    </script>

